package org.zdc.core;

class Version 
{
	private var majorRevision:Int;
	private var minorRevision:Int;
	private var maintenanceRevision:Int;
	private var updateRevision:Int;
	private var build:String;
	
	
	public function new(?majorRevision:Int = 0, ?minorRevision:Int = 0, ?maintenanceRevision:Int = 0, ?updateRevision:Int = 0, ?build:String)
	{
		if (majorRevision > 0x7f) {
			throw new IllegalArgumentException("majorRevision must be less than "
                + 0x7f + ".");
		}
		if (minorRevision > 0x7f) {
			throw new IllegalArgumentException("minorRevision must be less than "
                + 0x7f + ".");
		}
		if (maintenanceRevision > 0x7f) {
			throw new IllegalArgumentException("maintenanceRevision must be less than "
                + 0x7f + ".");
		}
		if (updateRevision > 0x7f) {
			throw new IllegalArgumentException("updateRevision must be less than "
                + 0x7f + ".");
		}
		
		this.majorRevision = majorRevision;
		this.minorRevision = minorRevision;
		this.maintenanceRevision = maintenanceRevision;
		this.updateRevision = updateRevision;
		this.build = build;
	}
	
	public function getMajorRevision():Int {
		return majorRevision;
	}
	
	public function getMinorRevision():Int {
		return minorRevision;
	}
	
	public function getMaintenanceRevision():Int {
		return maintenanceRevision;
	}
	
	public function getUpdateRevision():Int {
		return updateRevision;
	}
	
	public function getNumber():Int {
		var number:Int = ((this.majorRevision) & 0xff) << (8 * 3)
            | ((this.minorRevision) & 0xff) << (8 * 2)
            | ((this.maintenanceRevision) & 0xff) << (8 * 1)
            | ((this.updateRevision) & 0xff) << (8 * 0);

        return number;
	}
	
	public function compareTo(version:Version):Int {
		return (getNumber() - version.getNumber());
	}
	
	public function equals(version:Version):Bool {
		return (compareTo(version) == 0);
	}
	
	public static function decode(value:String):Version {
		throw new IllegalArgumentException("此方法未实现！");
		return null;
	}
}